package com.czy.seed.mvc.home.controller;
import com.czy.seed.mvc.home.entity.WarnInfo;
import com.czy.seed.mvc.home.service.WarnInfoService;
import com.czy.seed.mvc.util.NotePort;
import com.czy.seed.mvc.util.Res;
import com.czy.seed.mvc.util.SystemProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;

@RestController
@RequestMapping("/home/warnInfo")
public class WarnInfoController {
    public static Logger logger = LoggerFactory.getLogger(WarnInfo.class);

    private String STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    @Autowired
    private WarnInfoService warnInfoService;
    @Autowired
    SystemProperties systemProperties;
    //预警信息查询条件
    @RequestMapping("/selectStatistics")
    public Res selectStatistics() {
        Map<String, Object> pageInfo = new HashMap<String, Object>(16);
        ArrayList listType = new ArrayList();
        List<WarnInfo> warnText = warnInfoService.selectStatistics(systemProperties.getTotal());
        pageInfo.put("warnText", warnText);
        return Res.ok(pageInfo);
    }
    @RequestMapping("/sendInfo")
    public String sendInfo(String tel){
        String code = securityCode();
        //发送方电话
        String devicePhone = tel;
        //发送的短信内容
        String content ="【甘肃锐智科技】您好，您通过阳光云采服务平台进行手机注册，验证码是："+ code;
        NotePort notePort = new NotePort();
/*
        notePort.SendMessage("",systemProperties.getAccount(),systemProperties.getNotePwd(),devicePhone,content,"");
*/
        return  code;
    }
    /**
     *
     * 生成随机的四位验证码
     *
     * @return
     */
    /*@Scheduled(cron = "0 0 2 ? * *")*/
    public String securityCode() {
        StringBuilder sb = new StringBuilder(4);
        for (int i = 0; i < 4; i++) {
            char ch = STR.charAt(new Random().nextInt(STR.length()));
            sb.append(ch);
        }
        logger.info("===============生成的验证码信息为：{}", sb.toString());
        return sb.toString();


    }

}
